package top.kpromise.common.base;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.Date;

@Getter
@Setter
@ToString
@MappedSuperclass
public class BaseEntity {

    @Min(0)
    @Max(1)
    @ApiModelProperty(name = "deleted", value = "标记是否已经删除，1-删除，0-没有删除")
    @Column(columnDefinition = "tinyint(2) default 0 comment '标记是否已经删除，1-删除，0-没有删除'", insertable = false)
    private Integer deleted;

    @Min(0)
    @Max(1)
    @ApiModelProperty(name = "enabled", value = "标记是否已经启用，1-启用，0-未启用")
    @Column(columnDefinition = "tinyint(2) default 1 comment '标记是否已经启用，1-启用，0-未启用'", insertable = false)
    private Integer enabled;

    @Id()
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty(name = "id", value = "唯一ID，自增")
    @Column(updatable = false, insertable = false, nullable = false, columnDefinition = "BIGINT comment '唯一ID，自增'")
    private Long id;

    @ApiModelProperty(name = "orderNum", value = "排序")
    @Column(columnDefinition = "BIGINT not null default 1 comment '排序，小的在前'")
    private Long orderNum;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "create_time", insertable = false, updatable = false,
            columnDefinition = "datetime DEFAULT CURRENT_TIMESTAMP comment '创建时间'")
    @ApiModelProperty(name = "createAt", value = "创建时间")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "update_time", insertable = false, updatable = false,
            columnDefinition = "datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间'")
    @ApiModelProperty(name = "updateAt", value = "更新时间")
    private Date updateTime;
}
